const IO = require('koa-socket-2');
const socket = new IO();
module.exports = (app)=>{
    let roomindex = 0;
    socket.attach(app);
    console.log('socket')
    socket.on('message', (ctx, data) => {
        console.log('client sent data to message endpoint', ctx);
        socket.broadcast('news', {msg:'我是返回的消息... ...'});
    });
    socket.on('open', (ctx, data) => {
        console.log('client sent data to message endpoint', ctx.data.msg);
        ctx.socket.broadcast.emit('message', '我是返回的消息... ...');
    //     socket.on('send', data => {
    //         console.log('客户端发送的内容：', data);
    //    })
    });
    return socket;
}